﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ZLDC.Common.Estate;

namespace ZLDC.Topo.BLL.Estate
{
                public class OprAllPropertyBLL
    {
                                                                public static string p_opr_AllProperty_list_table(int userid, int page, int pagesize, string condition, string orderByName, string orderByType)
        {            
            DataTable dt = null;
            int total = 0;                       int pageall = 0;         
            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.OprAllPropertyDAL.p_opr_AllProperty_list_table(userid, page, pagesize, condition, orderByName, orderByType, ref total, db);
            }

            pageall = _Utility.GetPageAll(pagesize, total);      
            _Json json = new _Json(dt);
            return "{page:{currentpage:'" + page + "',pagesize:'" + pagesize + "',total:'" + total + "',pageall:'" + pageall + "'},record:" + json.ToJson() + "}";
        }

                                                public static string p_opr_AllProperty_detail_table(int Pty_id)
        {
            DataTable dt = null;
    
            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.OprAllPropertyDAL.p_opr_AllProperty_detail_table(Pty_id, db);
            }

            _Json json = new _Json(dt);
            return "{record:" + json.ToJson() + "}";
        }

                                                                        public static string p_opr_AllProperty_save(int userid, string username, int pty_id, int roomid)
        {
            string outmsg = "";

            using (_Database db = new _Database("estate"))
            {
                ZLDC.DAL.Estate.OprAllPropertyDAL.p_opr_AllProperty_save(userid, username, pty_id, roomid, out outmsg, db);
            }

            return outmsg;
        }

                                                        public static string p_opr_AllProperty_list_system_table(int newbuildid, int oldbuildid)
        {
            DataTable dt = null;
            string outmsg = "";

            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.OprAllPropertyDAL.p_opr_AllProperty_list_system_table(newbuildid, oldbuildid, 0, out outmsg, db);
            }

            _Json json = new _Json(dt);
            return "{record:" + json.ToJson() + "}";
        }

                                                        public static string p_opr_AllProperty_list_system_table(int newbuildid, int oldbuildid, int typeid)
        {
            DataTable dt = null;
            string outmsg = "";

            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.OprAllPropertyDAL.p_opr_AllProperty_list_system_table(newbuildid, oldbuildid, typeid, out outmsg, db);
            }

            _Json json = new _Json(dt);
            return "{record:" + json.ToJson() + "}";
        }

                                                        public static string NewSystemBuild_Auto(int top, string condition)
        {
            DataTable dt = null;

            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.OprAllPropertyDAL.NewSystemBuild_Auto(top, condition, db);
            }

            _Json json = new _Json(dt);
            return "{record:" + json.ToJson() + "}";
        }

                                                        public static string OldSystemBuild_Auto(int top, string condition)
        {
            DataTable dt = null;

            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.OprAllPropertyDAL.OldSystemBuild_Auto(top, condition, db);
            }

            _Json json = new _Json(dt);
            return "{record:" + json.ToJson() + "}";
        }

                                                        public static string NewSystemEstate_Auto(int top, string condition)
        {
            DataTable dt = null;

            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.OprAllPropertyDAL.NewSystemEstate_Auto(top, condition, db);
            }

            _Json json = new _Json(dt);
            return "{record:" + json.ToJson() + "}";
        }

                                                        public static string OldSystemEstate_Auto(int top, string condition)
        {
            DataTable dt = null;

            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.OprAllPropertyDAL.OldSystemEstate_Auto(top, condition, db);
            }

            _Json json = new _Json(dt);
            return "{record:" + json.ToJson() + "}";
        }

                                                        public static string p_opr_AllProperty_list_ok(int id, int typeid)
        {
            string outmsg = "";

            using (_Database db = new _Database("estate"))
            {
                ZLDC.DAL.Estate.OprAllPropertyDAL.p_opr_AllProperty_list_ok(id, typeid, out outmsg, db);
            }

            return outmsg;
        }

                                                        public static string p_build_lastlist_byeid_table(int eid, out string outmsg)
        {
            DataTable dt = null;

            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.OprAllPropertyDAL.p_build_lastlist_byeid_table(eid, out outmsg, db);
            }

            _Json json = new _Json(dt);
            return "{record:" + json.ToJson() + "}";
        }

                                                        public static string BuildOldSystem(int eid)
        {
            DataTable dt = null;

            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.OprAllPropertyDAL.BuildOldSystem(eid, db);
            }

            StringBuilder sb = new StringBuilder();
            sb.Append("<select id=\"oldBuildSelect_0\" name=\"oldBuildSelect_0\">");
            for (int i = 0; i < dt.Rows.Count; i++)
            {                
                sb.Append("<option value='" + dt.Rows[i]["id"].ToString() + "'>");
                sb.Append(dt.Rows[i]["name"].ToString());
                sb.Append("</option>");
            }
            sb.Append("</select>");

            return sb.ToString();
        }

                                                public static string p_housing_revoke(int bid)
        {
            string outmsg = "";

            using (_Database db = new _Database("estate"))
            {
                ZLDC.DAL.Estate.OprAllPropertyDAL.p_housing_revoke(bid, out outmsg, db);
            }

            return outmsg;
        }

                                                public static string EstateAllCancel(int eid)
        {
            string outmsg = "";

            using (_Database db = new _Database("estate"))
            {
                ZLDC.DAL.Estate.OprAllPropertyDAL.p_opr_AllProperty_list_cancel(eid, db);
            }

            return outmsg;
        }

                                                                                public static string OprAllPropertyList(int neweid, int oldeid, int page, int pagesize, string condition, string orderByName, string orderByType)
        {
            DataTable dt = null;
            int total = 0;                          int pageall = 0;                        int newcount = 0;                       int oldcount = 0;           
            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.OprAllPropertyDAL.p_opr_AllProperty_list2_table(neweid, oldeid, page, pagesize, condition, orderByName, orderByType, ref total, ref newcount, ref oldcount, db);
            }

            pageall = _Utility.GetPageAll(pagesize, total);      
            _Json json = new _Json(dt);
            return "{field:{newcount:'" + newcount + "',oldcount:'" + oldcount + "'},page:{currentpage:'" + page + "',pagesize:'" + pagesize + "',total:'" + total + "',pageall:'" + pageall + "'},record:" + json.ToJson() + "}";
        }

                                                public static int p_GetBidByPtyID(int ptyID)
        {
            int newbid = 0;

            using (_Database db = new _Database("estate"))
            {
                ZLDC.DAL.Estate.OprAllPropertyDAL.p_GetBidByPtyID(ptyID, out newbid, db);
            }

            return newbid;
        }
    }
}
